package com.fr.report;

import com.fr.base.core.list.IntList;

public class PageSetChain extends PageSet
{
  private ChainInfo[] chainInfos;
  private int pageCount = -1;
  private PageSetChain case4traversing = null;
  private Object traversing_lock = new Object();

  public PageSetChain(PageSet[] paramArrayOfPageSet)
  {
    this.chainInfos = new ChainInfo[paramArrayOfPageSet.length];
    for (int i = 0; i < paramArrayOfPageSet.length; ++i)
      this.chainInfos[i] = new ChainInfo(this, paramArrayOfPageSet[i], null);
    initPageCount();
  }

  private PageSetChain(ChainInfo[] paramArrayOfChainInfo)
  {
    this.chainInfos = paramArrayOfChainInfo;
    initPageCount();
  }

  private void initPageCount()
  {
    this.pageCount = 0;
    for (int i = 0; i < this.chainInfos.length; ++i)
    {
      ChainInfo.access$102(this.chainInfos[i], this.pageCount);
      if (ChainInfo.access$200(this.chainInfos[i]).sizePredictable())
      {
        this.pageCount += ChainInfo.access$200(this.chainInfos[i]).size();
        ChainInfo.access$302(this.chainInfos[i], this.pageCount - 1);
      }
      else
      {
        ChainInfo.access$302(this.chainInfos[i], 2147483647);
        this.pageCount = 2147483647;
        return;
      }
    }
  }

  public int size()
  {
    return this.pageCount;
  }

  public boolean sizePredictable()
  {
    for (int i = 0; i < this.chainInfos.length; ++i)
      if (!(ChainInfo.access$200(this.chainInfos[i]).sizePredictable()))
        return false;
    return true;
  }

  public boolean pageCached()
  {
    for (int i = 0; i < this.chainInfos.length; ++i)
      if (!(ChainInfo.access$200(this.chainInfos[i]).pageCached()))
        return false;
    return true;
  }

  public PageSet getTraversingCase()
  {
    synchronized (this.traversing_lock)
    {
      if (this.case4traversing == null)
      {
        ChainInfo[] arrayOfChainInfo = new ChainInfo[this.chainInfos.length];
        for (int i = 0; i < arrayOfChainInfo.length; ++i)
        {
          arrayOfChainInfo[i] = new ChainInfo(this, ChainInfo.access$200(this.chainInfos[i]).getTraversingCase(), null);
          ChainInfo.access$102(arrayOfChainInfo[i], ChainInfo.access$100(this.chainInfos[i]));
          ChainInfo.access$302(arrayOfChainInfo[i], ChainInfo.access$300(this.chainInfos[i]));
        }
        this.case4traversing = new PageSetChain(arrayOfChainInfo);
      }
    }
    return this.case4traversing;
  }

  public ReportPage getPage(int paramInt)
  {
    if (paramInt < 0)
      return null;
    for (int i = 0; i < this.chainInfos.length; ++i)
      if ((ChainInfo.access$100(this.chainInfos[i]) <= paramInt) && (paramInt <= ChainInfo.access$300(this.chainInfos[i])))
      {
        ReportPage localReportPage = ChainInfo.access$400(this.chainInfos[i], paramInt - ChainInfo.access$100(this.chainInfos[i]));
        if ((localReportPage == null) && (ChainInfo.access$300(this.chainInfos[i]) == 2147483647))
          synchronized (this)
          {
            if ((ChainInfo.access$300(this.chainInfos[i]) != 2147483647) || (!(sizePredictable())))
              break label136;
            initPageCount();
            if (paramInt <= this.pageCount - 1)
              break label127;
            return null;
            return getPage(paramInt);
          }
        localReportPage.getPageInfo().setTotalPages((this.pageCount == 2147483647) ? -1 : this.pageCount);
        localReportPage.setCurrentPageNumber(paramInt + 1);
        return localReportPage;
      }
    label136: label127: return null;
  }

  public IntList getChainPageInfo()
  {
    if ((!(pageCached())) || (!(sizePredictable())))
      return null;
    for (int i = 0; i < this.chainInfos.length; ++i)
      if (ChainInfo.access$300(this.chainInfos[i]) == 2147483647)
        synchronized (this)
        {
          if (ChainInfo.access$300(this.chainInfos[i]) != 2147483647)
            break label68;
          initPageCount();
          break label84:
        }
    label68: label84: IntList localIntList = new IntList(this.chainInfos.length);
    for (int j = 0; j < this.chainInfos.length; ++j)
      localIntList.add(ChainInfo.access$100(this.chainInfos[j]));
    return localIntList;
  }

  public PageSet getReportPageSet(int paramInt)
  {
    if ((this.chainInfos == null) || (this.chainInfos.length <= paramInt))
      return null;
    return ChainInfo.access$200(this.chainInfos[paramInt]);
  }

  public void release()
  {
    for (int i = 0; i < this.chainInfos.length; ++i)
      ChainInfo.access$200(this.chainInfos[i]).release();
    if (this.case4traversing != null)
      this.case4traversing.release();
  }

  private class ChainInfo
  {
    private int startIndex;
    private int endIndex;
    private PageSet pageSet;
    private final PageSetChain this$0;

    private ChainInfo(, PageSet paramPageSet)
    {
      this.this$0 = paramPageSetChain;
      this.pageSet = paramPageSet;
    }

    private ReportPage getReportPage()
    {
      return this.pageSet.getPage(paramInt);
    }

    ChainInfo(, PageSet paramPageSet, PageSetChain.1 param1)
    {
      this(paramPageSetChain, paramPageSet);
    }

    static int access$102(ChainInfo paramChainInfo)
    {
      return (paramChainInfo.startIndex = paramInt);
    }

    static PageSet access$200(ChainInfo paramChainInfo)
    {
      return paramChainInfo.pageSet;
    }

    static int access$302(ChainInfo paramChainInfo)
    {
      return (paramChainInfo.endIndex = paramInt);
    }

    static int access$100(ChainInfo paramChainInfo)
    {
      return paramChainInfo.startIndex;
    }

    static int access$300(ChainInfo paramChainInfo)
    {
      return paramChainInfo.endIndex;
    }

    static ReportPage access$400(ChainInfo paramChainInfo)
    {
      return paramChainInfo.getReportPage(paramInt);
    }
  }
}